package com.daodai.hjcjsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.daodai.hjcjsystem.domain.po.DeviceEntity;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface CollectionMapper extends BaseMapper<DeviceEntity> {


    /**
     * 重构的分页查询方法，增加了多表查询
     * @param page
     * @return
     */
    Page<DeviceEntity> selectBatch(IPage<DeviceEntity> page);

    /**
     * 第一次插入数据到device_realtime_value_now表中
     * @param deviceEntityList
     * @return
     */
    void saveToNowTable(@Param("deviceEntityList")List<DeviceEntity> deviceEntityList);


    /**
     * 更新value值到device_realtime_value_now表中
     * @param deviceEntityList
     */
    void updateToNowTable(@Param("deviceEntityList") List<DeviceEntity> deviceEntityList);

    /**
     * 根据id查询标志位信息
     * @return
     */
    @Select("select yethannyhj.device_realtime_value_now.value from yethannyhj.device_realtime_value_now where sid = 1")
    int selectFlag();

    /**
     * 将标志位置为1
     */
    @Update("update yethannyhj.device_realtime_value_now set yethannyhj.device_realtime_value_now.value = 1 where sid = 1")
    void changeFlag();

    /**
     * 初始化时进行删表操作
     */
    @Delete("delete from yethannyhj.device_realtime_value_now where sid > 1")
    void deleteAll();


    /**
     * 备份前一天数据到表中
     * @param tableName
     * @param deviceEntityList
     */
    void saveToSubtable(@Param("tableName") String tableName, @Param("deviceEntityList") List<DeviceEntity> deviceEntityList);

    /**
     * 插入数据到device_realtime_value表中
     * @param deviceEntityList
     */
    void insertBatch(@Param("deviceEntityList") List<DeviceEntity> deviceEntityList);

    /**
     * 按照时间删除表中数据
     * @param dateStartTime
     * @param dateEndTime
     */
    void deleteByTime(@Param("dateStartTime") LocalDateTime dateStartTime, @Param("dateEndTime") LocalDateTime dateEndTime);
}
